using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace IBuyAdventure
{



   public class OrdersDB
   {
      string m_ConnectionString;

      public OrdersDB( string dsn ) {
         m_ConnectionString = dsn;
      }
      public DataSet GetOrdersForCustomer(string customerName) {

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT * FROM Orders WHERE CustomerName='"+customerName+"'", sqlConnection);

          DataSet products = new DataSet();
          sqlAdapter1.Fill(products, "products");

          return products;
      }   
   
      public void AddNewOrder(string customerName, string ordered, double orderValue) {

          String insertStatement = "INSERT INTO Orders(CustomerName, Ordered, TotalValue) values ('" + customerName + "', '" + ordered + "' , '" + orderValue + "')";

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlCommand myCommand = new SqlCommand(insertStatement, sqlConnection);

          myCommand.Connection.Open();
          myCommand.ExecuteNonQuery();
          myCommand.Connection.Close();
      }

      public void DeleteOrdersForCustomer(string customerName) {
      
          String updateStatement = "Delete Orders where customerName ='" + customerName + "'";

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlCommand myCommand = new SqlCommand(updateStatement, sqlConnection);

          myCommand.Connection.Open();
          myCommand.ExecuteNonQuery();
          myCommand.Connection.Close();
      }

   }

}


